﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Skynet
{
    public partial class DomainsEditor : Form
    {
        public bool ProgramChanging;
        public DomainsEditor()
        {
            
            InitializeComponent();
        }

        private void DomainsEditor_Load(object sender, EventArgs e)
        {
            // fill the grids
            foreach (Domain domain in ((frmSkynet)(this.Tag)).domains.domList)
            {
                this.ucDom1.domains.domList.Add(domain);
            }
            foreach (Value value in ((frmSkynet)(this.Tag)).domains.valList)
            {
                this.ucDom1.domains.valList.Add(value);
            }
            
            this.ucDom1.pf = (frmSkynet)(this.Tag);
            
            
            //domains
            
            ucDom1.dgvDomian.Rows.Clear();
            ProgramChanging = true;
            foreach (Domain domain in this.ucDom1.domains.domList)
            {
                ucDom1.dgvDomian.Rows.Add(domain.Row);
            }

            //values

            ucDom1.dgvValue.Rows.Clear();
            if (ucDom1.dgvDomian.Rows[0]!=null)
            {
                foreach (Value value in this.ucDom1.domains.valList)
                {
                    if (value.domainRow == ucDom1.dgvDomian.Rows[0])
                    {
                        ucDom1.dgvValue.Rows.Add(value.Row);
                    }
                    
                }
            }
            
            ProgramChanging = false;
        }

        private void DomainsEditor_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!ucDom1.qqqq)
            {
                var dr = MessageBox.Show("Сохранить изменения", "Вопрос",
                                     MessageBoxButtons.YesNo,
                                     MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (dr == DialogResult.Yes)
                {
                    ucDom1.pf.domains = ucDom1.domains;
                }
            }
            
            
        }
    }
}
